package com.zhichat.web.api;

import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * @ClassName: PageUtils
 * @Description: 分页工具类
 * @Author: insanetz https://space.bilibili.com/602197686
 * @CreateDate: 2024/11/16 19:27
 */
@Data
public class PageUtils<V> implements Serializable {
    private static final long serialVersionUID = 1L;

    private int totalCount; //总记录数

    private int pageSize; //每页记录数

    private int totalPage; //总页数

    private int currPage; //当前页数

    private List<V> list; //列表数据

    /**
     * 分页
     *
     * @param list       列表数据
     * @param totalCount 总记录数
     * @param pageSize   每页记录数
     * @param currPage   当前页数
     */
    public PageUtils(List<V> list, int totalCount, int pageSize, int currPage) {
        this.list = list;
        this.totalCount = totalCount;
        this.pageSize = pageSize;
        this.currPage = currPage;
        this.totalPage = (int) Math.ceil((double) totalCount / pageSize);
    }

    public int getTotalPage() {
        return (int) Math.ceil((double) totalCount / pageSize);
    }
}
